package com.slb.slnwp.common.utils;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * @author: joinly
 * @date: 2022/5/6 11:33
 * @desc:
 **/
public class OkHttpClientUtil {

    private static final OkHttpClient okHttpClient = new OkHttpClient();

    /**
     * 使用 OkHttp 库发送 HTTP GET 请求的 Java 方法
     * @param url
     * @return
     * @throws IOException
     */
    public static String get(String url) throws IOException {
        // 置了请求的URL
        Request request = new Request.Builder().url(url).build();
        // 执行请求并返回相应内容
        Response response = okHttpClient.newCall(request).execute();
        return response.body().string();
    }
}
